﻿using Fozzy;
using System.Collections.Generic;
using System.Windows;

namespace Microsoft.FamilyShow
{
    /// <summary>
    /// This Enumeration of Files contains the recent Files manipulated by the Application
    /// Max 5 recent Files kept
    /// </summary>

    public class Recents                                                : Files
    {
        #region Declarations
        #endregion

        #region Properties
        #endregion

        #region Constructeur
            public Recents()                                            : base(5)
            {}
            public Recents(int max)                                     : base(max)
            {}
            /// <summary>
            /// Max 5 recent Files kept
            /// </summary>
            //public Recents(RoutedEventHandler handler)                  : base(handler)
            //{}
            public Recents(IEnumerable<File> files)                     : base(files)
            {}
        #endregion

        //App.RecentFiles.Remove(file);
        //App.RecentFiles.Insert(0, file);
            public override void Add(File part)
            {
                Remove(part)                                            ;
                Insert(0, part)                                         ;
                //base.Add(part)                                          ;
            }

            //public static void SaveRecentFiles()
            //{
            //    XmlSerializer ser = new XmlSerializer(typeof(StringCollection));
            //    using (TextWriter writer = new StreamWriter(RecentFilesFilePath))
            //    {
            //        ser.Serialize(writer, recentFiles);
            //    }
            //}

        //public static void LoadRecentFiles()
        //{
        //    if (File.Exists(RecentFilesFilePath))
        //    {
        //        // Load the Recent Files from disk
        //        XmlSerializer ser = new XmlSerializer(typeof(StringCollection));
        //        using (TextReader reader = new StreamReader(RecentFilesFilePath))
        //        {
        //            recentFiles = (StringCollection)ser.Deserialize(reader);
        //        }

        //        // Remove files from the Recent Files list that no longer exists.
        //        for (int i = 0; i < recentFiles.Count; i++)
        //        {
        //            if (!File.Exists(recentFiles[i]))
        //                recentFiles.RemoveAt(i);
        //        }

        //        // Only keep the 5 most recent files, trim the rest.
        //        while (recentFiles.Count > NumberOfRecentFiles)
        //            recentFiles.RemoveAt(NumberOfRecentFiles);
        //    }
        //}

        /// <summary>
        /// Save the list of recent files to disk.
        /// </summary>
        //Fozzy//public static void SaveRecentFiles()
        //{
        //    XmlSerializer ser = new XmlSerializer(typeof(StringCollection));
        //    using (TextWriter writer = new StreamWriter(RecentFilesFilePath))
        //    {
        //        ser.Serialize(writer, recentFiles);
        //    }
        //}

    }

    ///Fozzy saved : 
    //string RecentFilesFilePath =  Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),  Path.Combine(App.ApplicationFolderName, "RecentFiles.xml"));
    //private const int NumberOfRecentFiles = 5;
    /// <summary>
    /// Gets the list of recent files.
    /// </summary>
    //Fozzy//public static StringCollection RecentFiles
    //{
    //    get { return recentFiles; }
    //}
}
